package com.bjxst;

import java.io.*;

/**File类在IO中的作用：当以文件作为数据源或目标时，除了可以使用字符串作为
 * 文件以及位置的指定以外，也可以用File类指定*/
public class FileDemo {
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try{
            br = new BufferedReader(new FileReader(new File("d:/b.txt") ));
            bw = new BufferedWriter(new FileWriter(new File("d:/q.txt")));
            String temp = "";
            int i =1;
            while ((temp = br.readLine()) != null){
                bw.write(i+","+temp);
                bw.newLine();
                i++;
            }
            bw.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(br != null){
                    br.close();
                }
                if(bw != null){
                    bw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
